using System;
using System.Collections.Generic;
using System.Text;
using SP.Parameter;

namespace SP.HwLowProfileRS
{
    /// <summary>
    /// A simple base map feature
    /// </summary>
    public class LightMapFusion : AbstractFusion
    {
        public LightMapFusion()
        {
            AddPreprocessor(new Preprocessor("LIGHTMAP_2X", 0, 1, 1, "Set to 1 to enable 2x lightmap brightness."));

            // param lightMap
            AddParameter(
                new Texture2dParamter("lightMap", "lightMapSamp")
                .SetSRGBTexture(false)
                .SetForceSamplerId(2)
                .SetDesc("Lightmap (UV channel 3); RGB: color; A: unused.")
                );

            //AddParameter(new ScalarParameter("lightMapMultiplier")
            //    .SetS(1)
            //    .SetDesc("Lightmap multiplier [0.0 - 2.0].")
            //    );
        }

        public override string Name
        {
            get { return "LightMap"; }
        }

        public override string Desc
        {
            get { return "Enable this fusion to support static lightings."; }
        }

        public override Stage Stage
        {
            get { return Stage.Illumination; }
        }

        public override int UVChannelCount
        {
            get { return 3; }
        }

        public override void Code(StringBuilder b, string platform)
        {
            AddLine(b, "vec4 lightMap = tex2D(lightMapSamp, pipeline.Texcoord[2]);");
            AddLine(b, "#if LIGHTMAP_2X");
            AddLine(b, "lightMap = lightMap * 2.0;");
            AddLine(b, "#endif");
            AddLine(b, "pipeline.Illumination = lightMap.rgb;");
        }
    }
}
